<?php





    // Author: Tomasz Durka

    // Date: 5th February 2007

    // Prints out a link for PHP nails

    

    

  function href ($label, array $params = array()) {

    

    
    $url = '#';
    $rel = '';
    $generic = '';
    $confirm = '';
    $before = '';
    $on_click = '';
    $update = false;
    $serialize = false;
    $success = false;
    $complete = false;
    $style = '';
    $classes = array();
    $active_if = false;
    $display_if = true;
    
    
    foreach ($params as $_name => $_value) {
      switch ($_name) {
        case 'display_if':
          if (!$_value) return;
        break;
        case 'active_if':
          if ($_value) $classes[] = 'active';
        break;
        case 'id':
        case 'on_click':
          $$_name = $_value;
        break;
        case 'rel':
        case 'style':
        case 'name':
          $generic .= " {$_name}=\"{$_value}\"";
        break;
        case 'class':
          $classes[] = $_value;
        break;
        case 'confirm':
          $confirm = "if (!confirm('{$_value}')) return false;";
        break;
        case 'url':
          if ($_value ==  'back') {
            $url = $_SERVER['HTTP_REFERER'];
          } elseif (preg_match ('/^http:\/\//', $_value)) {
            $url = $_value;
          } else {
            $url = '/' . $_value;
          }
        break;
      }
    }
    
    $classes = implode (' ', array_unique($classes));
    $returned = "<a href=\"{$url}\" class=\"{$classes}\"{$generic} onClick=\"{$confirm}{$on_click}\">{$label}</a>";
    return $returned;
    
    
    
    
    
    
    

  /* 
    case 'on_click':
    $$_key = htmlspecialchars($_val);
    $$_key = str_replace("\r\n", "<!--\n-->", $$_key);
    $$_key = str_replace("\n", "\\n", $$_key);
    $$_key = str_replace("<!--\\n-->", "\r\n", $$_key);
    break;
  */
  }



?>